// token常量
const TokenKey = 'X-Access-Token';
// 用户常量
const UserInfo = 'User-Info';
// openid
const WechatOpenId = 'Wechat-Open-Id';
// phone
const PHONE = 'PHONE';
// unionId
const UNIONID = 'unionId';

// 获取token
export function getToken() {
	let token
	try {
		const value = uni.getStorageSync(TokenKey)
		if (value) {
			token = value
		}
	} catch (e) {
		console.log(e, tokenError)
	}
	return token
}

// 设置token
export function setToken(token) {
	try {
		uni.setStorageSync(TokenKey, token)
	} catch (e) {
		console.log(e, tokenError)
	}
}
// 清楚token
export function removeToken() {
	try {
	    uni.removeStorageSync(TokenKey)
	} catch (e) {
	    console.log(e, tokenError)
	}
}

// 获取用户信息
export function getUserInfo() {
	let userInfo
	try {
		const value = uni.getStorageSync(UserInfo)
		if (value) {
			userInfo = value
		}
	} catch (e) {
		console.log(e, tokenError)
	}
	return userInfo
}

// 设置用户信息
export function setUserInfo(userInfo) {
	try {
		uni.setStorageSync(UserInfo, userInfo)
	} catch (e) {
		console.log(e, tokenError)
	}
}


// 获取openid
export function getWechatOpenId() {
	let wechatOpenId
	try {
		const value = uni.getStorageSync(WechatOpenId)
		if (value) {
			wechatOpenId = value
		}
	} catch (e) {
		console.log(e, tokenError)
	}
	return wechatOpenId
}

// 设置token
export function setWechatOpenId(wechatOpenId) {
	try {
		uni.setStorageSync(WechatOpenId, wechatOpenId)
	} catch (e) {
		console.log(e, tokenError)
	}
}
// 清楚token
export function removeWechatOpenId() {
	try {
	    uni.removeStorageSync(WechatOpenId)
	} catch (e) {
	    console.log(e, tokenError)
	}
}


// 获取openid
export function getPhone() {
	let phone
	try {
		const value = uni.getStorageSync(PHONE)
		if (value) {
			phone = value
		}
	} catch (e) {
		console.log(e, tokenError)
	}
	return phone
}

// 设置token
export function setPhone(phone) {
	try {
		uni.setStorageSync(PHONE, phone)
	} catch (e) {
		console.log(e, tokenError)
	}
}
// 清楚token
export function removePhone() {
	try {
	    uni.removeStorageSync(PHONE)
	} catch (e) {
	    console.log(e, tokenError)
	}
}


// 获取unionId
export function getUnionId() {
	let unionId
	try {
		const value = uni.getStorageSync(UNIONID)
		if (value) {
			unionId = value
		}
	} catch (e) {
		console.log(e, tokenError)
	}
	return unionId
}

// 设置unionId
export function setUnionId(unionId) {
	try {
		uni.setStorageSync(UNIONID, unionId)
	} catch (e) {
		console.log(e, tokenError)
	}
}
// 清楚unionId
export function removeUnionId() {
	try {
	    uni.removeStorageSync(UNIONID)
	} catch (e) {
	    console.log(e, tokenError)
	}
}
